//
//  PYHttp.h
//  IHome
//
//   Created by zhujizheng on 2020/2/18.
//  Copyright © 2019年 com.zhujizheng. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, PYRequestType) {
    PY_GET = 0,
    PY_POST = 1,
    PY_DELETE = 2,
    PY_PUT = 3,
};

typedef NS_ENUM(NSInteger, PYBodyType) {
    PY_JSON = 0,
    PY_Form_Data = 1,
};

@interface PYHttp : NSObject

/**
 IHomeServer的网络请求

 @param URLString 接口地址
 @param parameters 参数
 @param requestType 请求类型
 @param success 请求成功的回调
 @param failure 请求失败的回调
 */
+ (void)requestIHomeServerWithURLString:(NSString *)URLString
                             parameters:(nullable id)parameters
                            requestType:(PYRequestType)requestType
                                success:(nullable void (^)(id _Nullable data))success
                                failure:(nullable void (^)(NSString * _Nullable message))failure;

/**
 通用网络请求

 @param URLString 接口地址
 @param parameters 参数
 @param requestType 请求类型
 @param bodyType 请求体类型
 @param success 请求成功的回调
 @param failure 请求失败的回调
 */
+ (void)requestWithURLString:(NSString *)URLString
                  parameters:(nullable id)parameters
                 requestType:(PYRequestType)requestType
                    bodyType:(PYBodyType)bodyType
                     success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success
                     failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure;

+ (void)uploadData:(NSData *)data
  progress:(nullable void (^)(float))progress
        completion:(nonnull void (^)(NSString * _Nullable))completion;

/// 下载文件
/// @param urlStr 文件url
/// @param path 文件保存的路径
/// @param progress 下载进度
/// @param completion 下载结果
+ (void)downloadFileWithUrl:(NSString *)urlStr
                       path:(NSString *)path
                   progress:(nullable void(^)(float percent))progress
                 completion:(void(^)(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error))completion;

@end

NS_ASSUME_NONNULL_END
